package com.briup.corejava.day21;

import java.io.*;
import java.net.Socket;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

/**
 * tcp客户端发送对象
 * 从文件中读取内容转为对象
 * 发送对象到服务器
 */
public class TcpClientObject {
    public static void main(String[] args) {
        Socket socket = null;
        File file = new File("src/com/briup/corejava/day21/stu.txt");
        BufferedReader br = null;
        ObjectOutputStream oos = null;
        try {
            socket = new Socket("127.0.0.1",8888);
            br = new BufferedReader(new FileReader(file));
            oos = new ObjectOutputStream(socket.getOutputStream());
            // 读取文件内容
            // 1、按行读取；2、根据点进行分割
            String line = null;
            // 准备集合接收
            List<User> list = new ArrayList<>();
            while ((line = br.readLine())!=null){
                String[] split = line.split("[.]");
                User user = new User(split[0],split[1],Integer.parseInt(split[2]));
                list.add(user);
            }
            oos.writeObject(list);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
